package com.example.administrator.im.utils;

import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.util.Log;

/**
 * create:2018/10/5 17:31
 * author: 姚鸿杰
 **/
public class DialogUtils {

    private static AlertDialog alert;
    private static AlertDialog.Builder builder;

    public static void setDialog(Context context, int layoutId) {
        if (builder == null)
            builder = new AlertDialog.Builder(context);
        builder.setView(layoutId);
        alert = builder.create();
        alert.setCanceledOnTouchOutside(false);
//        alert.setCancelable(false);
        alert.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                clearAlerDialog();
            }
        });
    }

    public static void showDialog() {
        if (alert != null)
            alert.show();
    }

    public static void clearAlerDialog() {
        if (alert != null)
            alert.dismiss();
        builder = null;
    }

}
